package com.trt.system.service.impl;

import com.github.pagehelper.PageHelper;
import com.trt.system.mapper.AdminUserMapper;
import com.trt.system.service.IAdminUserService;
import com.trt.api.service.BaseService;
import com.trt.pojo.AdminUser;
import com.trt.pojo.dto.AdminUserBO;
import com.trt.utils.PagedGridResult;
import org.n3r.idworker.Sid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @author tanrentao
 * @date 2021-12-03
 * @desc
 */
@Service
public class AdminUserServiceImpl extends BaseService implements IAdminUserService {

    @Autowired
    private AdminUserMapper adminUserMapper;

    @Autowired
    private Sid sid;

    @Override
    public AdminUser selectAdminUserByUsername(String username) {
        Example adminUserExample = new Example(AdminUser.class);
        Example.Criteria criteria = adminUserExample.createCriteria();
        criteria.andEqualTo("username", username);
        return adminUserMapper.selectOneByExample(adminUserExample);
    }

    @Transactional
    @Override
    public void createAdminUser(AdminUserBO adminUserBO) {

    }

    @Override
    public PagedGridResult selectAdminUserList(Integer page, Integer pageSize) {
        Example adminExample = new Example(AdminUser.class);
        adminExample.orderBy("createdTime").desc();
        PageHelper.startPage(page, pageSize);
        List<AdminUser> list = adminUserMapper.selectByExample(adminExample);
        return setterPagedGrid(list, page);
    }


}
